package com.ssy.lingxi.purchase.api.enums.needplan;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 需求计划记录 -操作状态枚举
 * @author lxc
 * @date 2022/02/25
 * @version 2.0.0
 */
public enum NeedPlanInnerOperationStatusEnum {

    ADD(1, "新增需求计划"),
    UPDATE(2, "修改需求计划"),
    SUBMIT(3, "提交需求计划"),
    EXAM1(4, "审核需求计划(一级)"),
    EXAM2(5, "审核需求计划(二级)"),
    COLLECT(6, "汇总需求计划"),
    RETURN(7, "退回需求计划"),
    UNLOCK(8, "解锁需求计划");
    private Integer code;
    private String message;

    NeedPlanInnerOperationStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static String getMessage(String message) {
        NeedPlanInnerOperationStatusEnum workEnum = Arrays.stream(NeedPlanInnerOperationStatusEnum.values()).filter(e -> e.getCHMessage().equals(message)).findFirst().orElse(null);
        return null == workEnum ? "" : LanguageHolder.getName(NeedPlanInnerOperationStatusEnum.class, workEnum.getCode());
    }

    public static String getMessage(Integer code) {
        NeedPlanInnerOperationStatusEnum workEnum = Arrays.stream(NeedPlanInnerOperationStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return null == workEnum ? "" : LanguageHolder.getName(NeedPlanInnerOperationStatusEnum.class, workEnum.getCode());
    }

    public static List<Map<String, Object>> getAll() {
        return Arrays.stream(NeedPlanInnerOperationStatusEnum.values()).map(a -> {
            String message = LanguageHolder.getName(NeedPlanInnerOperationStatusEnum.class, a.getCode());
            Map<String, Object> map = new HashMap<>();
            map.put("code", a.getCode());
            map.put("message", message);
            return map;
        }).collect(Collectors.toList());
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    /**
     * 字段类型为Integer
     * @return
     */
    public String getMessage() {
        return LanguageHolder.getName(this.getClass(), this.code);
    }

    /**
     * 字段类型为String
     * @return
     */
    public String getCHMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
